/*
 * Copyright (C) 2013 Fabiano Tarlao
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.easybenchmark.client.benchmarks;

import org.easybenchmark.client.testengines.scimark.FFT;

/**
 *
 * @author Fabiano Tarlao
 */
public class FFTBenchmark extends Benchmark{
    
    protected static int DEFAULT_NUMERIC_ARRAY_SIZE=32;
    protected int numericArraySize;
    
    double[] complexNumbersArray;

    public FFTBenchmark() {
        this(DEFAULT_NUMERIC_ARRAY_SIZE);
    }

    public FFTBenchmark(int numericArraySize) {
        setBenchmarkDescrition("Computes FFT's of complex, double precision data, GSL code taken from scimark");
        this.numericArraySize = numericArraySize;
    }
    
    //less is better
    protected double cumulativeRMS;
    
    @Override
    protected int initBenchTask() {
        complexNumbersArray = FFT.makeRandom(this.numericArraySize);  
        return(complexNumbersArray.length);
    }    
    
    @Override
    protected long benchTask() {
        cumulativeRMS+=FFT.startFFT(complexNumbersArray);
        //returns number of float operations needed
        return(Math.round((float) FFT.num_flops(complexNumbersArray.length)));
    }

    public double getCumulativeRMS() {
        return cumulativeRMS;
    }
    
    public double getAverageRMS(){
        return (lastShotNumberIteration!=0)? (cumulativeRMS/lastShotNumberIteration) : 0;
    }

    @Override
    protected int initWarmUpTask() {
         complexNumbersArray = FFT.makeRandom(DEFAULT_NUMERIC_ARRAY_SIZE);  
        return(complexNumbersArray.length);
    }
    
}
